import EventRoute from "./EventRoute"

const routers = new Array();

/**
 * 检查更新
 */
routers.push(
  new EventRoute('checking-for-update', 'event', (api, data = {}) => {
    console.log('checking-for-update')
  })
)

/**
 * 有可用更新
 */
routers.push(
  new EventRoute('update-available', 'event', (api, data = {}) => {
    console.log('update-available')
  })
)

/**
 * 无可用更新
 */
routers.push(
  new EventRoute('update-not-available', 'event', (api, data = {}) => {
    console.log('update-not-available')
    let interval = setInterval(() => {
      if(api.window.isReady()){
        api.loadingWindow.destroy()
        api.window.show()
        clearInterval(interval)
      }
    }, 1000)
  })
)

/**
 * 下载更新
 */
routers.push(
  new EventRoute('download-progress', 'event', (api, data = {}) => {
    console.log('download-progress')
  })
)

/**
 * 下载更新完成
 */
routers.push(
  new EventRoute('update-downloaded', 'event', (api, data = {}) => {
    console.log('update-downloaded')
  })
)

/**
 *  登陆成功
 */
routers.push(
  new EventRoute('login-success', 'event', (api, data = {}) => {
    const { width, height } = api.screen.size
    const windowWidth = width * 0.9
    const windowHeight = height * 0.8
    api.window.setMaximizable(true)
    api.window.setResizable(true)
    api.window.setSize(Math.floor(windowWidth), Math.floor(windowHeight))
    api.window.setMinimumSize(Math.floor(windowWidth), Math.floor(windowHeight))
    api.window.setPosition(Math.floor((width - windowWidth) / 2), Math.floor((height - windowHeight) / 2))
  })
)
/**
 *  退出登录
 */
routers.push(
  new EventRoute('logout-success','event',(api, data = {})=>{
    const { width, height } = api.screen.size
    api.window.reset()
    const windowSize = api.window.getSize()
    const windowWidth = windowSize[0]
    const windowHeight = windowSize[1]
    api.window.setPosition(Math.floor((width - windowWidth) / 2), Math.floor((height - windowHeight) / 2))
  })
)

/**
 *  关闭窗口
 */
routers.push(
  new EventRoute('close-window', 'event', (api, data = {}) => {
    api.app.quit()
  })
)

/**
 * 窗口最小化
 */
routers.push(
  new EventRoute('mini-window', 'event', (api, data = {}) => {
    api.window.minimize()
  })
)

/**
 * 默认浏览器，打开URL
 */
routers.push(
  new EventRoute('open-browser-url', 'event', (api, data = {}) => {
    api.shell.openExternal(data.data)
  })
)
export default routers
